package me.myqaq.myqaqcraft.slimefunaddon.supper;

import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactivity;
import io.github.thebusybiscuit.slimefun4.core.attributes.WitherProof;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import org.bukkit.block.Block;
import org.bukkit.entity.Wither;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;

public class axe_one extends SlimefunItem implements Radioactive, WitherProof {

    public  axe_one(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
        super(itemGroup, item, recipeType, recipe);
    }

     //定义 Radioactive 接口中的 getRadioactivity() return返回一个辐射伤害
        @Override
        public Radioactivity getRadioactivity(){
            return Radioactivity.HIGH;
       }
    @Override
        public void onAttack(@Nonnull Block block, @Nonnull Wither wither) {
            wither.setHealth(0);
        }
    @Override
        public void preRegister() {

            BlockUseHandler blockUseHandler=this::onBlockRightClick;
            addItemHandler(blockUseHandler);

            ItemUseHandler itemUseHandler=this::onItemUseRightClick;
            addItemHandler(itemUseHandler);
        }

        private void onBlockRightClick(PlayerRightClickEvent event){

           event.cancel();

          int ello =  event.getPlayer().getLevel();

            if ( ello>=30){
                    event.getPlayer().giveExpLevels(-30);
                    event.getPlayer().setFireTicks(5*20);
                    event.getPlayer().sendMessage("§4谁让你摸我的！！！");
            }else{
                    event.getPlayer().sendMessage("§4he~呸！30级经验都没有！死~杂~鱼~");
                    event.getPlayer().setHealth(0);
            }
        }

        private void onItemUseRightClick(PlayerRightClickEvent event) {
            // 如果在这里调用 event.cancel() 会阻止玩家放置蛋糕
            event.getPlayer().giveExpLevels(1);
            event.getPlayer().sendMessage("§a给你一点经验。偷着乐吧");

        }
}
